// 4. 服务层实现
package com.ruoyi.teaching.service;

import com.ruoyi.system.domain.TeachingDesign;
import com.ruoyi.system.domain.TeachingDesignContent;
import com.ruoyi.system.service.ITeachingDesignContentService;
import com.ruoyi.system.service.ITeachingDesignService;
import com.ruoyi.teaching.http.TeachingDesignHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeachingDesignService {

    @Autowired
    private TeachingDesignHttpClient teachingDesignHttpClient;

    @Autowired
    private ITeachingDesignService teachingDesignService;

    @Autowired
    private ITeachingDesignContentService teachingDesignContentService;

    /**
     * 生成教学设计
     */
    public SseEmitter generateTeachingDesign(String subject, Long teacherId, Long classId, String title) {
        return teachingDesignHttpClient.generateTeachingDesign(subject, teacherId, classId, title);
    }

    /**
     * 获取教学设计详情
     */
    public Map<String, Object> getTeachingDesignDetail(Long id) {
        Map<String, Object> result = new HashMap<>();

        // 查询主表信息
        TeachingDesign design = teachingDesignService.selectTeachingDesignById(id);
        if (design == null) {
            return result;
        }

        result.put("design", design);

        // 查询内容表信息
        List<TeachingDesignContent> contents = teachingDesignContentService.selectTeachingDesignContentByDesignId(id);
        Map<String, String> contentMap = new HashMap<>();

        for (TeachingDesignContent content : contents) {
            contentMap.put(content.getContentType(), content.getContent());
        }

        result.put("contents", contentMap);
        return result;
    }
}
